package ch01.shangji.shangji2;

import java.lang.reflect.Field;

public class Person extends JavaBean implements java.io.Serializable{
    public static void main(String[] args) throws ClassNotFoundException, IllegalAccessException, InstantiationException, NoSuchFieldException {
        Class clz = Class.forName("ch01.shangji.shangji2.JavaBean");
        Object javabean = clz.newInstance();

        //获取name属性
        Field name = clz.getDeclaredField("name");
        //设为可访问的
        name.setAccessible(true);
        //为取值贬值的name
        System.out.println("前：" + name.get(javabean));
        //给name属性赋值
        name.set(javabean, "我是大帅哥");
        //取值赋值后
        System.out.println("后：" + name.get(javabean));
    }
}
